home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gwu / adaed / gwudemos / worms.ada < prev   
Encoding:
Text File  |  1996-01-30  |  2.6 KB  |  73 lines

  1. --
  2. --    Program : Worms.ada
  3. --    Purpose : This program is based on the UNIX game worms.  It is
  4. --      implemented to show how tasks can be used in ADA.  It
  5. --      is interesting since the Worms program could really be
  6. --      implemented as a sequential program.  This implementation
  7. --      shows how tasks can be used to simplify the design of a
  8. --      sequential program.  By defining the Worms as individual
  9. --      tasks, the programmer only has to worry about defining the
  10. --      behavior of a single Worm, and then creating multiple 
  11. --      instantiations of that Worm.
  12. --
  13. --    To use with GWUMON : To use this program with GWUMON, from the command
  14. --              line type:
  15. --                       adacomp -a -b -mworms worms.ada
  16. --                       gwumon -mworms
  17. --
  18. --    On the intial setup screen, choose 'Y' to the questions if tasks are
  19. --          used.  Also, set the intial speed to 10, the fastest speed 
  20. --      (the monitor will still run slow.  To get a better feel for
  21. --      how the worms run, try running it once not through the
  22. --      monitor).  The first four windows which will show up will be
  23. --      the main procedure WORMS, the task SCREEN, and two instances
  24. --      of the WORM task.  Notice how the WORM task interacts with
  25. --      SCREEN task.  
  26. --      
  27.  
  28. WITH Text_IO; USE Text_IO;
  29. WITH My_Int_IO;
  30. WITH Screen; USE Screen;
  31. WITH Creatures; USE Creatures;
  32. PROCEDURE Worms IS
  33.     TYPE W_Array IS ARRAY(INTEGER RANGE <>) of Creatures.Worm;
  34.     TYPE Worms_Array IS ACCESS W_Array;
  35.     OnScreen : Worms_Array;
  36.     Number_Of_Worms : INTEGER;
  37. BEGIN
  38.     LOOP
  39.         PUT_LINE( "Enter the number of worms (1-6) " );
  40.         My_Int_IO.GET( Number_Of_Worms );
  41.         IF  Number_Of_Worms < 1 OR Number_Of_Worms > 6 THEN
  42.         PUT_LINE ( "Invalid number of worms, use 1-6" );
  43.         ELSE
  44.         EXIT;
  45.         END IF;
  46.     END LOOP;
  47.  
  48.     OnScreen := NEW W_Array( 1..Number_Of_Worms );
  49.     PUT_LINE( "Enter the screen Size (Min X, Y, Max X, Y)");
  50.     My_Int_IO.GET( Minimum_xy.x );
  51.     My_Int_IO.GET( Minimum_xy.y );
  52.         My_Int_IO.GET( Maximum_xy.x );
  53.     My_Int_IO.GET( Maximum_xy.y );
  54.     ClearScreen;
  55.         OnScreen(1).Init_Worm( '@' );
  56.     IF Number_Of_Worms >1 THEN
  57.             OnScreen(2).Init_Worm( '#' );
  58.     END IF;
  59.     IF Number_Of_Worms >2 THEN
  60.             OnScreen(3).Init_Worm( '$' );
  61.     END IF;
  62.     IF Number_Of_Worms >3 THEN
  63.             OnScreen(4).Init_Worm( '%' );
  64.     END IF;
  65.     IF Number_Of_Worms >4 THEN
  66.         OnScreen(5).Init_Worm( '&' );
  67.     END IF;
  68.     IF Number_Of_Worms >5 THEN
  69.         OnScreen(6).Init_Worm( '*' );
  70.     END IF;
  71. END Worms;
  72.  
  73.